<template>
  <div class="dayin">
    <el-button type="primary" @click="print()" class="dayin_btn">打印预览</el-button>
    <!-- <el-popconfirm
      confirm-button-text="好的"
      cancel-button-text="不用了"
      icon-color="red"
      title="是否将此订单设置为待发货？"
      @confirm="set_DeliveryStatus"
    >
      <el-button  type="primary" slot="reference" style="margin-bottom: 10px;"> 打印预览</el-button>
    </el-popconfirm> -->

    <div ref="print" id="printArea">
      <h3 style="text-align: center">{{ Infomation }}</h3>
      <!-- <span style="display:block;text-align: center;margin-top:-10px;margin-bottom:10px;">{{formatterTime(bottoms.order_date)}}</span> -->
      <div class="div_span">
        <div>
          <span>客户： {{ bottoms.customer_name }}</span>
          <span>客户电话：{{ bottoms.contact_phone }}</span>
          <span>日期：{{ formatterTime(bottoms.order_date) }}</span>
        </div>
        <div>
          <span style="word-break: break-all">物流地址： {{ bottoms.customer_address }}</span>
          <span style="margin-right: 150px;">物流信息：{{bottoms.logistics}}</span>
        </div>

      </div>
      <table class="table_tbs" style="border-collapse: collapse" cellspacing="0">
        <tr>
          <td class="td_1">订单号</td>
          <td class="td_1">型号</td>
          <td class="td_1">颜色</td>
          <td class="td_1">规格</td>
          <td class="td_1">尺寸</td>
          <td class="td_1">方向</td>
          <td class="td_1">件数</td>
        </tr>
        <tr style="width: 100%" v-for="(item, index) in dayinlist" :key="index">
          <td class="td_1">
            {{ item.order.order_number }}
          </td>
          <td class="td_1">
            {{ item.order.model_number_name ? item.order.model_number_name.model_number : "" }}
          </td>
          <td class="td_1">
            {{ item.order.color ? item.order.color.color : "" }}
          </td>
          <td class="td_1">
            {{ item.order.specification ? item.order.specification.specification : "" }}
          </td>
          <td class="td_1">
            {{ item.models_field ? item.models_field.size : "" }}
          </td>
          <td class="td_1">
            {{ item.order.direction }}
          </td>
          <td class="td_1">
            {{ item.num }}
          </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td>合计件数</td>
          <td>{{ order_num }}</td>
        </tr>
      </table>
      <div class="list_order">
        <div class="left">
          <div class="lis">
            <el-row>
              <el-col :span="12"> 出货仓库 : </el-col>
              <el-col :span="12">

              </el-col>
            </el-row>
          </div>
          <div class="lis">
            <el-row>
              <el-col :span="12"> 出库经手人 : </el-col>
              <el-col :span="12">

              </el-col>
            </el-row>
          </div>
          <div class="lis">
            <el-row>
              <el-col :span="12"> 业务员 : </el-col>
              <el-col :span="12">
                {{ bottoms.company_name }}
              </el-col>
            </el-row>
          </div>


        </div>


        <div class="right">

          <div class="lis">
            <el-row>
              <el-col :span="12"> 收货人签字 : </el-col>
              <el-col :span="12"> </el-col>
            </el-row>
          </div>
        </div>
        <div style="page-break-after: always"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { setDeliveryStatus } from "@/api/product/index";
export default {
  data() {
    return {
      dayinlist: [],
      strDate: "",
      bottoms: {
        warehouse_name: "",
        num: "",
        order_number:'',
        company_name: "",
        receivables: "",
        balance: "",
        qiankuan: "",
        contact_phone: "",
        customer_address: "",
        customer_name: "",
        order_date: "",
        logistics:''
      },
      Infomation: "",
      order_num: "",
    };
  },
  mounted() {
    this.dayinlist = JSON.parse(this.$route.query.data);
    this.Infomation = this.$store.getters.Infomation.company_name;
    this.currentTime();
    console.log(this.dayinlist);
    this.bottoms.balance = this.dayinlist[0].order.customer.balance;
    this.bottoms.company_name = this.dayinlist[0].order.account_executive?this.dayinlist[0].order.account_executive.company_name:''
    this.bottoms.contact_phone = this.dayinlist[0].order.customer.contact_phone;
    this.bottoms.customer_address = this.dayinlist[0].order.customer.customer_address;
    this.bottoms.customer_name = this.dayinlist[0].order.customer.customer_name;
    this.bottoms.order_date = this.dayinlist[0].order.order_date;
    this.bottoms.order_number = this.dayinlist[0].order.order_number;
    this.bottoms.logistics = this.dayinlist[0].order.customer.logistics
    this.dayinlist.forEach((item) => {
      this.order_num = Number(this.order_num) + Number(item.num);
    });
  },
  methods: {
    formatterTime(data) {
      if(data){
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data).splice(0, 11)[0];
      }else{
        return this.strDate
      }
     
    },
    set_DeliveryStatus() {
      let ids_s = [];
      this.dayinlist.forEach((item) => {
        ids_s.push(item.id);
      });
      setDeliveryStatus({ ids: ids_s }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.print();
        }
      });
    },
    /**
     * 获取当前时间
     */
    currentTime() {
      var date = new Date();
      var year = date.getFullYear(); //月份从0~11，所以加一
      let month = date.getMonth();
      console.log("month", month);
      var dateArr = [
        date.getMonth() + 1,
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
      ];
      //如果格式是MM则需要此步骤，如果是M格式则此循环注释掉
      for (var i = 0; i < dateArr.length; i++) {
        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
          dateArr[i] = "0" + dateArr[i];
        }
      }
      this.strDate =
        year +
        "/" +
        dateArr[0] +
        "/" +
        dateArr[1] +
        " " +
        dateArr[2] +
        ":" +
        dateArr[3] +
        ":" +
        dateArr[4];
    },
    print() {
      this.$print(this.$refs.print);
    },
  },
};
</script>
<style scoped>
.dayin {
  padding: 25px;
  box-sizing: border-box;
}

/* 
长 75mm
宽 45mm */
#printArea {
  width: 195mm;
  height: 80mm;
  padding: 10px;
  box-sizing: border-box;
  margin: 0 auto;
}

#printArea>div:first-child {
  margin-top: 0px;
}

#printArea table {
  width: 100%;
  border-collapse: collapse;
}

#printArea table th {
  color: #333;
  padding: 5px 0;
  font-size: 26px;
}

#printArea table {
  border: 1px solid #000;
}

#printArea table td,
table th {
  border: 1px solid #000;
  text-align: center;
  padding: 0;
  margin: 0;
}

#printArea table tr td {
  padding: 10px;
  box-sizing: border-box;
  font-size: 16px;
  word-break: break-all;
}

/* #printArea table thead th {
  background-color: #0a8fa1;
} */

#printArea table tr th,
table tr td {
  padding: 5px 12px;
}

.procedure {
  word-wrap: break-word;
}

.dayin_btn {
  background: #0a8fa1;
  border: none;
  margin: 20px 0;
}

.list_order {
  width: 210mm;
  margin: 0 auto;
  display: flex;
  font-size: 16px;
  justify-content: space-between;
}

.list_order .left {
  width: 300px;
}

.list_order .right {
  width: 300px;
}

.list_order .left .lis {
  margin-top: 15px;
}

.list_order .right {
  margin-right: 100px;
}

.list_order .right .lis {
  margin-top: 15px;
}

.div_span {
  margin-bottom: 5px;
}

.div_span div {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.div_span span {
  display: block;
  font-size: 16px;
}

h3 {
  font-weight: 500;
  font-size: 16px;
}

/* .table_tb{
  font-size: 16px;
} */
.table_tb tr {
  display: flex;
  /* display: grid; */
  /* grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr; */
  /* display: flex;
  justify-content: space-between; */
}

.table_tb tr td {
  font-size: 16px;
  display: block;
  height: auto;
  word-break: break-all;

}

.table_tbs {
  /* border-top: none !important; */
}

@media print {
  .dayin {
    padding: 25px;
    box-sizing: border-box;
  }

  /* 
长 75mm
宽 45mm */
  #printArea {
    width: 195mm;
    height: 80mm;
    padding: 10px;
    box-sizing: border-box;
    margin: 0 auto;
  }

  #printArea>div:first-child {
    margin-top: 0px;
  }

  #printArea table {
    width: 100%;
    border-collapse: collapse;
  }

  #printArea table th {
    color: #333;
    padding: 5px 0;
    font-size: 26px;
  }

  #printArea table {
    border: 1px solid #000;
  }

  #printArea table td,
  table th {
    border: 1px solid #000;
    text-align: center;
    padding: 0;
    margin: 0;
  }

  #printArea table tr td {
    padding: 10px;
    box-sizing: border-box;
    font-size: 16px;
    word-break: break-all;
  }

  /* #printArea table thead th {
  background-color: #0a8fa1;
} */

  #printArea table tr th,
  table tr td {
    padding: 5px 12px;
  }

  .procedure {
    word-wrap: break-word;
  }

  .dayin_btn {
    background: #0a8fa1;
    border: none;
    margin: 20px 0;
  }

  .list_order {
    width: 210mm;
    margin: 0 auto;
    display: flex;
    font-size: 16px;
    justify-content: space-between;
  }

  .list_order .left {
    width: 300px;
  }

  .list_order .right {
    width: 300px;
  }

  .list_order .left .lis {
    margin-top: 15px;
  }

  .list_order .right {
    margin-right: 100px;
  }

  .list_order .right .lis {
    margin-top: 15px;
  }

  .div_span {
    margin-bottom: 5px;
  }

  .div_span div {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
  }

  .div_span span {
    display: block;
    font-size: 16px;
  }

  h3 {
    font-weight: 500;
    font-size: 16px;
  }

  /* .table_tb{
  font-size: 16px;
} */
  .table_tb tr {
    display: flex;
    /* display: grid; */
    /* grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr; */
    /* display: flex;
  justify-content: space-between; */
  }

  .table_tb tr td {
    font-size: 16px;
    display: block;
    height: auto;
    word-break: break-all;

  }

  .table_tbs {
    /* border-top: none !important; */
  }
}</style>
